******************************************************************************
* Replication do file for:
* How Global Performance Assessments Shape Attitudes towardGovernment Decision-Making: Survey Experimental Evidence
* Davies, Emmerich, Gift, Thomas and Lastra-Anadón, Carlos X.
* Forthcoming in Governance
*Version 1.1 (2020-05-07)
*For questions, please get in touch with Carlos X Lastra-Anadón (clastra@faculty.ie.edu)
******************************************************************************

clear

******************************************************************************
* Installing packages
******************************************************************************

/*
ssc install balancetable
ssc install estout
ssc install sutex
*/

******************************************************************************
* Setting Directories
******************************************************************************

loc user : env USERPROFILE
if "`user'" == "C:\Users\A" {
	use "`user'/Dropbox/Research/Underway/gpa/submissions/2019-11 Governance/final edits/data/GPA data.dta"
	* Change directory for output
	cd "`user'/Dropbox/Research/Underway/gpa/submissions/2019-11 Governance/final edits/data/output"
}
else {
	* Please add the directory path where you are storing the file "GPA data.dta" here
	* use "~/GPA Replication materials/GPA data.dta"
}

******************************************************************************
* Labelling variables for export:
******************************************************************************

lab var treatment "GPA"
lab var scare "Scare"
lab var scaretreat "GPA x Scare"
lab var scarecontrol "NPA x Scare"
lab var shametreat "GPA x Shame"
lab var edispriority "Ed is priority"
lab var anychildren "Parent"
lab var left "Left"
lab var grade "Grade given to schools (1-5)"
lab var female "Female"
lab var nonwhite "Non-White"
lab var actualhispanic "Hispanic"
lab var actualage "Age"
lab var collegegraduate "College Graduate"
lab var salaryincome "Salary Income"
lab var moderate "Moderate"

******************************************************************************
* Setting locals
******************************************************************************

loc us if liveinus == 1
loc demographic nonwhite actualhispanic actualage
loc labormarket collegegraduate salaryincome

******************************************************************************
* Table 2
******************************************************************************

eststo clear
reg federalcontrol treatment `us', r
eststo federalcont0

reg federalcontrol scare `us', r
eststo federalcont1

reg federalcontrol treatment `demographic' `labormarket' left moderate anychildren `us', r
eststo federalcont0cov
estadd loc cov "X"

reg federalcontrol scare `demographic' `labormarket' left moderate anychildren `us', r
eststo federalcont1cov
estadd loc cov "X"

esttab federalcont0 federalcont1 federalcont0cov federalcont1cov using "federalmaintreatments2.tex", se r2 l star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab federalcont0 federalcont1 federalcont0cov federalcont1cov using "Table 2.rtf", se r2 l star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace keep(treatment scare) scalar("cov Individual covariates") title("Table 2: Effects of GPA and Scare Primes on Preferences for Federal Control") nonotes addnotes("Linear probability models. Robust standard errors in parentheses." "+ p < 0.10, * p < 0.05, ** p < 0.01, *** p < 0.001")

****************************************************************************** 
*Table 3
******************************************************************************

eststo clear

reg federalcontrol scaretreat scarecontrol shametreat `us', r
eststo federalcontbytreat2
reg federalcontrol scaretreat scarecontrol shametreat `demographic' `labormarket' left moderate anychildren `us', r
eststo federalcontbytreat3
estadd loc cov "X"

esttab federalcontbytreat2 federalcontbytreat3 using "federalsubtreatments.tex",  se r2 l star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab federalcontbytreat2 federalcontbytreat3 using "Table 3.rtf", replace keep(scaretreat scarecontrol shametreat) title("Table 3: Effects of GPA and Scare Primes on Preferences for Federal Control, with Interactions") se r2 l star(+ 0.10 * 0.05 ** 0.01 *** 0.001) scalar("cov Individual covariates") nonotes addnotes("Linear probability models. Each cell shows the marginal effect of receiving the prime pair over the omitted category (NPA x Shame). Robust standard errors in parentheses." "+ p < 0.10, * p < 0.05, ** p < 0.01, *** p < 0.001")

******************************************************************************
*Table 4
******************************************************************************

eststo clear

* Generating interaction terms for export
g scareedispriority = scaretreat * edispriority
g scarechildren = scaretreat * anychildren
g scareleft = scaretreat * left
lab var scareedispriority "GPA x Scare x Ed is priority"
lab var scarechildren "GPA x Scare x Parent"
lab var scareleft "GPA x Scare x Left"

reg federalcontrol scareedispriority scaretreat edispriority scarecontrol shametreat `us', r
reg federalcontrol i.scaretreat#i.edispriority scarecontrol shametreat `us', r
eststo federalcontpriority

reg federalcontrol scarechildren scaretreat anychildren scarecontrol shametreat `us', r
reg federalcontrol i.scaretreat#i.anychildren scarecontrol shametreat `us', r
eststo federalcontanychild

reg federalcontrol scareleft scaretreat left scarecontrol shametreat `us', r
reg federalcontrol i.scaretreat#i.left scarecontrol shametreat `us', r
eststo federalcontleft

esttab federalcontpriority federalcontanychild federalcontleft using "subgroups.tex", noconstant se r2 l star(+ 0.10 * 0.05 ** 0.01 *** 0.001) append
esttab federalcontpriority federalcontanychild federalcontleft using "Table 4.rtf", noconstant se r2 l star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace title("Table 4: Effects of GPA and Scare Primes on Preferences for Federal Control, with Interactions by Subgroups") order(scareedispriority scarechildren scareleft edispriority anychildren left shametreat scaretreat scarecontrol) nonotes addnotes("Linear probability models. Models do not include individual covariates. Robust standard errors in parentheses." "+ p < 0.10, * p < 0.05, ** p < 0.01, *** p < 0.001")
esttab federalcontpriority federalcontanychild federalcontleft using "Table 4.rtf", noconstant se r2 l star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace title("Table 4: Effects of GPA and Scare Primes on Preferences for Federal Control, with Interactions by Subgroups") order(1.scaretreat#1.edispriority 1.scaretreat#1.anychildren 1.scaretreat#1.left 0.scaretreat#1.edispriority 0.scaretreat#1.anychildren 0.scaretreat#1.left shametreat 1.scaretreat#0.edispriority 1.scaretreat#0.anychildren 1.scaretreat#0.left scarecontrol) interaction(" x ") keep(0.scaretreat#1.edispriority 1.scaretreat#0.edispriority 1.scaretreat#1.edispriority scarecontrol shametreat 0.scaretreat#1.anychildren 1.scaretreat#0.anychildren 1.scaretreat#1.anychildren 0.scaretreat#1.left 1.scaretreat#1.left 1.scaretreat#0.left) coeflabels(1.scaretreat#1.edispriority "GPA x Scare x Ed is priority" 1.scaretreat#1.anychildren "GPA x Scare x Parent" 1.scaretreat#1.left "GPA x Scare x Left" 0.scaretreat#1.edispriority "Ed is priority" 0.scaretreat#1.anychildren "Parent" 0.scaretreat#1.left "Left" shametreat "GPA x Shame" 1.scaretreat#0.edispriority "GPA x Scare" 1.scaretreat#0.anychildren "GPA x Scare" 1.scaretreat#0.left "GPA x Scare" scarecontrol "NPA x Scare") nonotes addnotes("Linear probability models. Models do not include individual covariates. Robust standard errors in parentheses." "+ p < 0.10, * p < 0.05, ** p < 0.01, *** p < 0.001")

****************************************************************************** 
*Table 5
******************************************************************************

eststo clear

reg increasefundschool shametreat scaretreat scarecontrol `us', r
eststo increasedfunds

reg grade shametreat scaretreat scarecontrol `us', r
eststo grade

reg edreformsupport shametreat scaretreat scarecontrol `us', r
eststo edreform

esttab increasedfunds grade edreform using "gpamainNocontrolsus.tex",  noconstant se r2 l  star(+ 0.10 * 0.05 ** 0.01 *** 0.001) append
esttab increasedfunds grade edreform using "Table 5.rtf", replace noconstant b(4) se(4) r2 l  star(+ 0.10 * 0.05 ** 0.01 *** 0.001) order(scaretreat scarecontrol shametreat) title("Table 5: Effects of GPA and Scare Primes on Alternative Outcomes") nonotes addnotes("Linear probability models in Models 1 and 3 (support binarized), and linear model with 1-5 outcome in Model 2, with 5 being the highest grade. Models do not include individual covariates. Robust standard errors in parentheses." "+ p < 0.10, * p < 0.05, ** p < 0.01, *** p < 0.001")

******************************************************************************
* Figure 1
******************************************************************************

*Margin graphs
set scheme s2mono
 
* Left Subfigure
reg federalcontrol i.treatment `us', r
margins treatment

marginsplot, xtitle(" ") graphregion(color(white)) recast(bar) ytitle("Share favoring greater federal control")   ///
title("GPA and NPA primes") ciopts(recast(rcap)) plotopts(barw(.6))  ylabel(0 (.1) .4, nogrid) level(90) ///
xlabel(0 "NPA" 1 " GPA" ) ///
xscale(range(-.5 1.5) )
graph save Graph "GPAplot.gph", replace

*Right Subfigure
reg federalcontrol i.scare `us', r
margins scare

marginsplot, xtitle(" ") graphregion(color(white)) recast(bar) ytitle("")   ///
title("Scare and Shame primes") ciopts(recast(rcap)) plotopts(barw(.6))  ylabel(0 (.1) .4, nogrid) level(90) ///
xlabel(0 "Shame" 1 "Scare" ) ///
xscale(range(-.5 1.5) )
graph save Graph "Scareplot.gph", replace

graph combine "GPAplot.gph" "Scareplot.gph"
graph export "Figure 1.eps", replace

******************************************************************************
*Figure 2
******************************************************************************

* Margin graphs
drop treatno
gen treatno=0 if shamecontrol==1
replace treatno=1 if scarecontrol==1
replace treatno=2 if shametreat==1
replace treatno=3 if scaretreat==1

reg federalcontrol i.treatno `us', r
margins treatno 

marginsplot,    xtitle(" ") graphregion(color(white)) recast(bar) ytitle("Share favoring greater federal control")   ///
	 title(" ") ciopts(recast(rcap)) plotopts(barw(.6))  ylabel(0 (.1) .4, nogrid) level(90) ///
	  xlabel(0 `"  "NPA X" "Shame" "' 1 `"  "NPA X" "Scare" "'  2 `"  "GPA X" "Shame" "' 3 `"  "GPA X" "Scare""' ) ///
	 xscale(range(-.5 3.5) )
	 graph save Graph "Basicplot.png", replace
	 graph export "Figure 2.eps", replace
	
******************************************************************************
* Appendix
******************************************************************************

******************************************************************************
* Table S1 Summary statistics
*Balance table Summary by subgroups
******************************************************************************

balancetable (mean) (mean if treatno == 0) (mean if treatno == 1) ///
(mean if treatno == 2) (mean if treatno == 3)  ///
female `demographic' `labormarket' left moderate anychildren `us' & ///
federalcontrol < . using "Table S1.xlsx", replace varlabels ///
ctitles("Full Sample" "NPA x Shame" "NPA x Scare" "GPA x Shame" "GPA x Scare") ///
leftctitle("") nonumbers female `demographic' `labormarket' left moderate anychildren `us' & federalcontrol < . using "balancetable.xls", replace
   
******************************************************************************
*Table S2 (table 3 with post stratification weights)
******************************************************************************

sum female `demographic'  `labormarket' left moderate anychildren `us' & federalcontrol<.
sutex female `demographic'  `labormarket' left moderate anychildren `us' & federalcontrol<.
sutex female `demographic'  `labormarket' `us'

gen femweight = 1.123057972 if female == 1
replace femweight = 1 / 1.123057972 if female == 0

sum female `demographic' `labormarket' `us' [iw = femweight]

gen nonwhweight = 3.19726123 if nonwhite == 1
replace nonwhweight = 1 if nonwhite == 0

gen femnonwweight = femweight * nonwhweight
sum female `demographic' `labormarket' `us' [iw = femnonwweight]

gen collegegradweight = 0.431360916 if collegegraduate == 1
replace collegegradweight = 1 / 0.431360916 if collegegraduate == 0

gen femnonwcollweight = femweight * nonwhweight * collegegradweight

sum female `demographic' `labormarket' `us' [iw = femnonwcollweight]

eststo clear

reg federalcontrol scaretreat scarecontrol shametreat `us' [iw = femnonwcollweight], r
eststo federalcontbytreat1
reg federalcontrol scaretreat scarecontrol shametreat `demographic' `labormarket' left moderate anychildren `us' [iw = femnonwcollweight], r
eststo federalcontbytreat2
estadd loc cov "X"

esttab federalcontbytreat1 federalcontbytreat2 using "poststrat.tex", noconstant se r2 l star(+ 0.10 * 0.05 ** 0.01 *** 0.001) append
esttab federalcontbytreat1 federalcontbytreat2 using "Table S2.rtf", replace noconstant se r2 l star(+ 0.10 * 0.05 ** 0.01 *** 0.001) keep(scaretreat scarecontrol shametreat) title("Table S2: Effects of GPA and Scare Primes on Preferences for Federal Control, with Interactions Using Post-Stratification Adjustment") scalar("cov Individual covariates") nonotes addnotes("Linear probability models. Same models as in Table 3 are run, using post-stratification weights to adjust our sample to the share of females, non-whites, and college graduates in the U.S. population. Robust standard errors in parentheses." "+ p < 0.10, * p < 0.05, ** p < 0.01, *** p < 0.001")

******************************************************************************
*Table S3 (Logit version of Table 2) 
******************************************************************************

eststo clear
logit federalcontrol treatment `us', r
eststo federalcont0

logit federalcontrol scare `us', r
eststo federalcont1

logit federalcontrol treatment `demographic' `labormarket' left moderate anychildren `us', r
eststo federalcont0cov
estadd loc cov "X"

logit federalcontrol scare `demographic' `labormarket' left moderate anychildren `us', r
eststo federalcont1cov
estadd loc cov "X"

esttab federalcont0 federalcont1 federalcont0cov federalcont1cov using "Logitfederalmaintreatments2.tex", se r2 l star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab federalcont0 federalcont1 federalcont0cov federalcont1cov using "Table S3.rtf", replace noconstant se l star(+ 0.10 * 0.05 ** 0.01 *** 0.001) keep(treatment scare) title("Table S3: Logit Model Effects of GPA and Scare Primes on Preferences for Federal Control") scalar("cov Individual covariates") nonotes addnotes("Coefficients from logit models, analogous to linear probability models in Table 2. Robust standard errors in parentheses." "+ p < 0.10, * p < 0.05, ** p < 0.01, *** p < 0.001")

******************************************************************************
*Table S4 (Logit version of Table 3)
******************************************************************************

eststo clear

logit federalcontrol scaretreat scarecontrol shametreat `us', r
eststo federalcontbytreat2
logit federalcontrol scaretreat scarecontrol shametreat `demographic' `labormarket' left moderate anychildren `us', r
eststo federalcontbytreat3

esttab federalcontbytreat2 federalcontbytreat3 using "federalsubtreatments.tex", se r2 l  star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab federalcontbytreat2 federalcontbytreat3 using "Table S4.rtf", replace se l  star(+ 0.10 * 0.05 ** 0.01 *** 0.001) keep(scaretreat scarecontrol shametreat) title("Table S4: Logit Model Effects of GPA and Scare Primes on Preferences for Federal Control, with Interactions") nonotes addnotes("Coefficients from logit models, analogous to linear probability models in Table 3. Robust standard errors in parentheses." "+ p < 0.10, * p < 0.05, ** p < 0.01, *** p < 0.001")
